package edu.scdx.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.scdx.common.util.JsonUtil;
import edu.scdx.entity.Trans;
import edu.scdx.entity.User;
import edu.scdx.service.UserInfoService;
import edu.scdx.service.UserService;
import edu.scdx.service.TransService;

@Controller
@RequestMapping("/trans")
public class TransController {
	
	@Autowired
	private TransService transService;

	public TransService getTransService() {
		return transService;
	}

	public void setTransService(TransService transService) {
		this.transService = transService;
	}
	
	@RequestMapping("/giveTrans.do")
    public String giveTrans(Model model,HttpSession session,String address,String phone,String postcode,String name){	
									
				
		String userTel=(String) session.getAttribute("userTel");
		
		Trans trans=transService.getTrans(userTel);
		
		if(trans==null){
			transService.addTrans(userTel,address,phone,postcode,name);
		}
		else {
			transService.updateTrans(userTel,address,phone,postcode,name);
		}
		
		
    	return "order";
    }

}
